#ifndef baskets_h
#define baskets_h
/*
 * this file contains usefull template functions/classes that
 * relate to the handling of conatainers and elements in
 * containers.
 */
 namespace design
 {
	#include <list>
	
	template <class _T>
 	class pointer_list : public std::list< _T * >
 	{
 		public:
 			typedef typename std::list< _T * > base_type;
 			typename base_type::iterator find(_T* p)
 			{
				base_type::iterator it = begin();
				while (it!=end())
				{
					if (p == *it)
						return it;
					it++;
				}
				return end();
 			}
 			
 			void clear()
 			{
	 			typename base_type::iterator it;
     			it	= begin();
	 			while (it != end())
 				{
 					delete (*it);
 					it++;
 				}
 				base_type::clear();
			}

 			void clone_from(const base_type &source)
 			{
 				clear();
				typename base_type::const_iterator it = source.begin();
    			while (it != source.end())
       			{
       				push_back(new _T(*(*it)));
       				it++;
          		}				
 			}
 	};
 	
	template <class _T>
 	class aggregate_ptr_list : public pointer_list<_T>
 	{
 		public:
	 		~aggregate_ptr_list<_T>()
 			{
 				clear();
 			}
 	};
}
#endif
